import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
import BasicLayout from '@/layouts/BasicLayout.vue';
import BlankLayout from '@/layouts/BlankLayout.vue';

// only githubpages preview site used, if use template please remove this check
// and use `createWebHistory` is recommend
const hasGithubPages = import.meta.env.VITE_GHPAGES;


const exceptionRoutes = [
  {
    path: '/err403',
    name: 'err403',
    meta: { title: '403', icon: 'icon-icon-test', hide: true },
    component: () => import("@/views/exception/403.vue"),
  },
  {
    path: '/err500',
    name: 'err500',
    meta: { title: '500', icon: 'icon-icon-test', hide: true },
    component: () => import("@/views/exception/500.vue"),
  },
  {
    path: '/*',
    name: 'err404',
    meta: { title: '404', icon: 'icon-icon-test', hide: true },
    component: () => import("@/views/exception/404.vue"),
  },
]

export default createRouter({
  history: hasGithubPages ? createWebHashHistory() : createWebHistory(),
  routes: [
    // {
    //   path: '/',
    //   name: 'login',
    //   meta: { title: '登录', icon: 'icon-icon-test', hide: true },
    //   component: () => import("@/views/login/index.vue"),
    // },
    {
      path: '/',
      name: 'index',
      meta: { title: 'Home' },
      component: BasicLayout,
      redirect: '/project',
      children: [
        {
          path: '/project/save/:id(\\d+)?',
          name: 'projectsave',
          meta: { title: '项目详情', icon: 'icon-icon-test', hide: true },
          component: () => import("@/views/project/Save.vue"),
        },
        {
          path: '/project',
          name: 'project',
          meta: { title: '项目', icon: 'icon-icon-test' },
          component: () => import("@/views/project/List.vue"),
        },
        {
          path: '/server',
          name: 'server',
          meta: { title: '服务器', icon: 'icon-icon-test' },
          component: () => import("@/views/server/List.vue"),
        },
        {
          path: '/configration',
          name: 'configration',
          meta: { title: '配置中心', icon: 'icon-icon-test' },
          component: () => import("@/views/configration/List.vue"),
        },
        // {
        //   path: '/admins',
        //   name: 'admins',
        //   meta: { title: '管理页', icon: 'icon-tuijian', flat: true },
        //   component: BlankLayout,
        //   redirect: () => ({ name: 'page1' }),
        //   children: [
        //     {
        //       path: 'page-1',
        //       name: 'page1',
        //       meta: { title: '一级页面' },
        //       component: () => import('../views/admins/PageInfo.vue'),
        //     },
        //     {
        //       path: 'page-2',
        //       name: 'page2',
        //       meta: { title: '二级页面' },
        //       component: () => import('../views/admins/PageTypography.vue'),
        //     },
        //     {
        //       path: 'dynamic-match/:id(\\d+)',
        //       name: 'dynamic-match',
        //       // 路由 path 默认参数再 meta.params 里
        //       meta: { title: '动态参数页面', params: { id: 1 } },
        //       component: () => import('../views/admins/DynamicMatch.vue'),
        //     },
        //   ],
        // }
        ...exceptionRoutes
      ],
    },
    {
      path: '/**',
      name: 'err404',
      meta: { title: '404', icon: 'icon-icon-test' },
      component: () => import("@/views/exception/404.vue"),
    },
  ]
});
